package com.inspur.gs.sbssdl.sbssgl.sbtz.sbtz.front.sbsssbtztreelisthelp_hlp.voactions;
import com.inspur.edp.bff.api.manager.context.QueryContext;
import com.inspur.edp.bff.spi.action.query.BeforeQueryAction;
import com.inspur.edp.cef.entity.condition.FilterCondition;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class QuerBeforeVOAction extends BeforeQueryAction {

	public QuerBeforeVOAction(QueryContext context){
		super(context);
	}
	@Override
	public void execute() {
		ArrayList<FilterCondition> fList = this.getQueryContext().getFilter().getFilterConditions();
		Optional<FilterCondition> lbbhOp = fList.stream().filter(i -> i.getFilterField().equals("sblb_id_lbbh")).findFirst();
		if (!lbbhOp.isPresent()){
			return;
		}
		ArrayList<FilterCondition> newFList = fList.stream()
				.filter(i -> !i.getFilterField().equals("sblb_id_lbbh"))
				.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);

		FilterCondition lbbhFC = lbbhOp.get();
		FilterCondition sblbLbbh = FilterCondition.builder()
				.orLikeStartWith("sblb_id_lbbh", lbbhFC.getValue())
				.build().get(0);

		newFList.add(sblbLbbh);

		this.getQueryContext().getFilter().setFilterConditions(newFList);

	}
}
